package com.jinlejia.erp.ui.mine.assist;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ActivityAssistAignatureBinding;
import com.sevenheaven.segmentcontrol.SegmentControl;

/**
 * 我的协助签单
 */
public class AssistAignatureActivity extends AppCompatActivity implements AssistantFragment.FragmentInteraction {

    private FragmentManager fm;
    private FragmentTransaction ft;
    private int segmentIndex = 0;


    private int type = -1;
    private int state = -1;
    private int userState = -1;
    public String startTime = "";
    public String endTime = "";

    private ActivityAssistAignatureBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_assist_aignature);
        binding.setEvent(this);
        initView();
    }

    private void initView() {
        fm = getSupportFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.content, new InitiatorFragment());
        ft.commitAllowingStateLoss();

        binding.assistControl.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
            @Override
            public void onSegmentControlClick(int index) {
                segmentIndex = index;
                FragmentManager fm = getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                switch (index) {
                    case 0://发起人
                        binding.imgSearch.setVisibility(View.GONE);
                        ft.replace(R.id.content, new InitiatorFragment());
                        ft.commitAllowingStateLoss();
                        break;
                    case 1://协助人
                        binding.imgSearch.setVisibility(View.VISIBLE);
                        ft.replace(R.id.content, new AssistantFragment());
                        ft.commitAllowingStateLoss();
                        break;
                    default:
                        break;
                }
            }
        });
    }

    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                finish();
                break;
            case R.id.img_search://搜索
                Intent intent = new Intent();
                intent.setClass(this, AssistAignatureSearchActivity.class);


                intent.putExtra("type", type);
                intent.putExtra("state", state);
                intent.putExtra("userState", userState);
                intent.putExtra("initiateTimeMin", startTime);
                intent.putExtra("initiateTimeMax", endTime);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void process(String startTime, String endTime, int type, int state, int userState) {
        this.startTime = startTime;
        this.endTime = endTime;
        this.type = type;
        this.state = state;
        this.userState = userState;
    }
}
